package com.hr.reactive.mono.s02;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

public class Lec04MonoEmptyTest {
    private static final Logger log = LoggerFactory.getLogger(Lec04MonoEmptyTest.class);

    public static void main(String[] args) {
    //    getUserName(1).subscribe(Utils.subscriber());
        // getUserName(2).subscribe(Utils.subscriber());
        //getUserName(3).subscribe(Utils.subscriber());
        getUserName(3).subscribe(s-> System.out.println(s),
                e->{ //提供错误处理程序
                    System.out.println(e);
                });
    }

    private static Mono<String> getUserName(int userId) {
        return switch (userId) {
            case 1 -> Mono.just("sam");
            case 2 -> Mono.empty();//null
            default -> Mono.error(new RuntimeException("error"));
        };
    }


}
